package com.coocaa.x.service.litecontent;

import android.os.IBinder;

import com.coocaa.x.framework.app.CoocaaApplication;
import com.coocaa.x.service.XServiceManager;
import com.coocaa.x.service.litecontent.aidl.ILiteContentService;

public class LiteContentServiceConnecter {
    private static final String ACTION = "com.coocaa.x.service.litecontent2";
    private static ILiteContentService service = null;

    public static void init() {
        XServiceManager.registerService(CoocaaApplication.getContext().getPackageName(), ACTION);
    }

    public synchronized static ILiteContentService getService() {
        if (service == null || !service.asBinder().isBinderAlive()) {
            IBinder binder = null;
            while (binder == null) {
                try {
                    init();
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                binder = XServiceManager.getService(ACTION);
            }
            service = ILiteContentService.Stub.asInterface(binder);
        }
        return service;
    }
}